package com.hanhai.zrb.backend.admin.dao.mybatis;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import com.hanhai.zrb.api.biz.dao.mybatis.base.BaseMapper;
import com.hanhai.zrb.backend.admin.model.BackUser;
import com.hanhai.zrb.backend.admin.model.BackendUser;
import com.hanhai.zrb.backend.admin.model.Privilege;

public interface BackUserDao extends BaseMapper{

	
	@Select("select id,email,is_enabled as isEnabled,login_name as loginName,memo,password,phone,user_name as userName,create_time as createTime from back_user where login_name=#{loginName} and is_enabled=1")
	BackendUser findByLoginNameForLogin(String loginName);
	
	@Select("select * from back_user where login_name=#{loginName} and is_enabled=true")
	BackUser findByLoginName(String loginName);
	
	@Select("select u.*,ur.role_id from back_user u left join back_user_role ur on u.id = ur.user_id order by id desc")
	List<Map<String, Object>> listAll();
	
	@Select("select * from back_user where id = #{id}")
	Map<String, Object> getBackUser(Integer id);
	
	void addBackUser(Map<String, Object> params);

	void updateBackUser(Map<String, Object> params);
	
	@Select("select p.acl,p.name,p.url,p.pacl as parentAcl,"
			+ "p.privilege_level, p.sort_no,p.enname from  back_user_role ur,"
			+ "role_privilege rp,privilege p "
			+ "where ur.role_id = rp.role_id and rp.acl = p.acl and ur.user_id = #{userId} order by p.privilege_level,p.sort_no,p.acl")
	@Deprecated
	List<Privilege> findPrivilegeByUserId(Long userId);
	
	List<Map<String, Object>> listPage();
	

	//@Update("update user set umobile=#{umobile},uemail=#{uemail},uname=#{uname},password=#{password},idcard=#{idcard} where uid=#{uid}")
	void update(Map<String,Object> user);

	@Select("select * from back_user where user_name like '${userName}%'")
	List<BackUser> searchByName(@Param("userName")String userName);
	
	@Select("select * from back_user where id = #{uid}")
	@ResultMap("backUserResultMap")
	BackUser getByUid(Long uid);
}
